<template>
  <div class="dashboard">
    <!-- 顶部数据统计 -->
    <div class="top-stats">
      <div class="stat-item">
        <span>今日完成订单:</span>
        <strong>{{ todayOrders }}</strong>
      </div>
      <div class="stat-item">
        <span>本周新增用户:</span>
        <strong>{{ weekNewUsers }}</strong>
      </div>
      <div class="stat-item">
        <span>本周入驻店铺:</span>
        <strong>{{ weekNewStores }}</strong>
      </div>
      <div class="stat-item">
        <span>本周招募配送员:</span>
        <strong>{{ weekNewDeliveryMen }}</strong>
      </div>
    </div>

    <!-- 快捷工具 -->
    <div class="quick-tools">
      <ul>
        <li><i class="fas fa-bullhorn"></i> 发布平台通知</li>
        <li><i class="fas fa-ad"></i> 发布广告投放</li>
        <li><i class="fas fa-check"></i> 发布报名活动</li>
        <li><i class="fas fa-yen-sign"></i> 发布平台活动</li>
        <li><i class="fas fa-water"></i> 添加配送站</li>
        <li><i class="fas fa-truck"></i> 添加配送员</li>
        <li><i class="fas fa-question-circle"></i> 添加常见问题</li>
        <li><i class="fas fa-cloud-rain"></i> 添加恶劣天气</li>
        <li><i class="fas fa-keyword"></i> 添加敏感词</li>
        <li><i class="fas fa-user"></i> 添加子账号</li>
      </ul>
    </div>

    <div>
      <div class="one" style="width:100%;height:400px;"></div>
    </div>

    <div>
      <div class="two" style="width:100%;height:400px;"></div>
    </div>
  </div>




</template>

<script>
import {
  listShangpin,
  getShangpin,
  delShangpin,
  addShangpin,
  updateShangpin,
  listSpshenhe, listDianpu
} from "@/api/shangpin/shangpin";
export default {
  name: "Index",
  data() {
    return {
      todayOrders: 77051,
      weekNewUsers: 4000,
      weekNewStores: 400,
      weekNewDeliveryMen: 1500,
      yesterdayA: 8.063,
      weekB: 2763,
      weekC: 205,
      lastWeekA: 1.065,
      shangpinList: [],
      nameList:[],
      yueshouList:[],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      listShangpin(null).then(response => {
        this.shangpinList = response.rows;
        // let nameList = [];
        // let yueshouList = [];
        for (let i in response.rows){
          this.nameList.push(response.rows[i].spName)
          this.yueshouList.push(response.rows[i].spYueshou)
        }
        console.log(this.nameList);
        console.log(this.yueshouList);


        // 初始化第一个图表
        let chart = this.$echarts.init(document.querySelector('.one'));
        chart.setOption({
          title: {
            text: "月销售演示",
          },
          tooltip: {},
          legend: {
            data: ["销量"],
          },
          xAxis: {
            data: this.nameList,
          },
          yAxis: {},
          series: [
            {
              name: "销量",
              type: "bar",
              data: this.yueshouList,
            },
          ],
        });

        // 初始化第二个图表
        let chart1 = this.$echarts.init(document.querySelector('.two'));
        chart1.setOption({
          title: {
            text: "月销售演示",
          },
          tooltip: {},
          legend: {
            data: ["销量"],
          },
          xAxis: {
            type: 'category',
            data: this.nameList,
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              name: "销量",
              type: "line",
              data: this.yueshouList,
            },
          ],
        });
      });

    },
},


};
</script>
<style scoped lang="scss">
.dashboard {
  display: flex;
  flex-direction: column;
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  margin: 20px;

  .top-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
    div {
      background-color: #fff;
      padding: 10px;
      border-radius: 4px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex: 1 0 25%;
      span {
        font-size: 16px;
        font-weight: 500;
      }

      strong {
        font-size: 20px;
        color: #333;
        font-weight: bold;
      }
    }
  }

  .quick-tools {
    ul {
      list-style: none;
      padding: 0;
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      li {
        background-color: #f5f7fa;
        padding: 10px;
        border-radius: 4px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        font-size: 14px;
        color: #333;
        text-align: center;
        flex: 1 0 20%;
        transition: background-color 0.3s ease;
        &:hover {
          background-color: #dfe6f0;
          cursor: pointer;
        }
      }
    }
  }

  div[ref="echarts"] {
    margin-top: 20px;
    border: 1px solid #ebeef5;
  }
}

/* Font Awesome icon styles */
.fas {
  font-size: 18px;
  margin-right: 5px;
}
</style>
